package com.duyan.learning;

import java.util.ArrayList;

/**
 * insertion sort
 * @author DuyAn
 * 
 */
public class InsertionSort {
	public int[] sort(int[] myValueList) {
		int j;
		for (int i = 1; i < myValueList.length; i++) {
			j = i;
			int tmp = myValueList[i];
			while ((j > 0) && (myValueList[j - 1] > tmp)) {
				myValueList[j] = myValueList[j - 1];
				j--;
			}
			myValueList[j] = tmp;
		}
		return myValueList;
	}
	public void sortArrayList(ArrayList<Integer> myValueList) {
		int j;
		for (int i = 1; i < myValueList.size(); i++) {
			j = i;
			int tmp = myValueList.get(i);
			while ((j > 0) && (myValueList.get(j-1) > tmp)) {
				myValueList.set(j,myValueList.get(j-1));
				j--;
			}
			myValueList.set(j,tmp);
		}
		//return myValueList;
	}

}
